package io.renren.modules.commodity.controller;

import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.commodity.entity.CommodityImgEntity;
import io.renren.modules.commodity.service.CommodityImgService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 商品图片
 *
 * @author xianwenchao
 * @email 1140617792@qq.com
 * @date 2021-01-31 01:22:43
 */
@RestController
@Api(value = "商品图片")
@RequestMapping("commodity/commodityimg")
public class CommodityImgController {
    @Autowired
    private CommodityImgService commodityImgService;

    /**
     * 商品图片列表
     */
    @GetMapping("/list")
    @RequiresPermissions("commodity:commodityimg:list")
    @ApiOperation(value = "查询商品图片列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = commodityImgService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 根据id查询商品图片信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("commodity:commodityimg:info")
    @ApiOperation(value = "根据id查询商品图片信息")
    public R info(@PathVariable("id") Long id){
		CommodityImgEntity commodityImg = commodityImgService.getById(id);

        return R.ok().put("commodityImg", commodityImg);
    }

    /**
     * 新增商品图片记录
     */
    @PostMapping("/save")
    @RequiresPermissions("commodity:commodityimg:save")
    @ApiOperation(value = "新增商品图片记录")
    public R save(@RequestBody CommodityImgEntity commodityImg){
		commodityImgService.save(commodityImg);

        return R.ok();
    }

    /**
     * 根据id修改商品图片记录
     */
    @PostMapping("/update")
    @RequiresPermissions("commodity:commodityimg:update")
    @ApiOperation(value = "根据id修改商品图片信息")
    public R update(@RequestBody CommodityImgEntity commodityImg){
		commodityImgService.updateById(commodityImg);

        return R.ok();
    }

    /**
     * 根据id删除商品图片记录
     */
    @PostMapping("/delete")
    @RequiresPermissions("commodity:commodityimg:delete")
    @ApiOperation(value = "根据id删除商品图片记录(非逻辑删除，建议不使用)")
    public R delete(@RequestBody Long[] ids){
		commodityImgService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
